package com.bingxue.edu.management.education.controller;

import com.bingxue.edu.common.enums.OperateSourceEnum;
import com.bingxue.edu.framework.common.model.PageQuery;
import com.bingxue.edu.framework.common.model.Pagination;
import com.bingxue.edu.framework.common.model.Response;
import com.bingxue.edu.framework.security.ApiResource;
import com.bingxue.edu.management.education.model.query.ClassCancelQuery;
import com.bingxue.edu.management.education.model.query.ClassChangeQuery;
import com.bingxue.edu.management.education.model.req.ClassCancelReq;
import com.bingxue.edu.management.education.model.req.ClassCancelVerifyReq;
import com.bingxue.edu.management.education.model.req.ClassChangeReq;
import com.bingxue.edu.management.education.model.req.ClassChangeRevertReq;
import com.bingxue.edu.management.education.model.resp.ClassCancelDetailResp;
import com.bingxue.edu.management.education.model.resp.ClassCancelResp;
import com.bingxue.edu.management.education.model.resp.ClassChangeDetailResp;
import com.bingxue.edu.management.education.model.resp.ClassChangeResp;
import com.bingxue.edu.management.education.service.ClassCancelService;
import com.bingxue.edu.management.education.service.ClassChangeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 转班/调课
 *
 * @author zq
 * @since 2024/08/22
 */
@Tag(name = "转班/调课")
@RestController
@RequestMapping("/education/class")
@RequiredArgsConstructor
public class ClassChangeController {

    private final ClassChangeService classChangeService;
    private final ClassCancelService classCancelService;

    @Operation(summary = "转班调课")
    @ApiResource("edu:class-change:manage")
    @PostMapping("/change/create")
    public Response<Void> crateClassChangeRecord(@RequestBody @Validated ClassChangeReq req) {
        req.setOperateSource(OperateSourceEnum.BACKEND);
        classChangeService.createClassChangeRecord(req);
        return Response.success();
    }

    @Operation(summary = "撤销调课")
    @ApiResource("edu:class-change:manage")
    @PostMapping("/change/revert")
    public Response<Void> revertClassChange(@RequestBody @Validated ClassChangeRevertReq req) {
        req.setOperateSource(OperateSourceEnum.BACKEND);
        classChangeService.revertClassChange(req);
        return Response.success();
    }

    @Operation(summary = "退班退课")
    @ApiResource("edu:class-cancel:manage")
    @PostMapping("/cancel/create")
    public Response<Void> createClassCancelRecord(@RequestBody @Validated ClassCancelReq req) {
        req.setOperateSource(OperateSourceEnum.BACKEND);
        classCancelService.createClassCancelRecord(req);
        return Response.success();
    }

    @Operation(summary = "通过退班退课审批")
    @ApiResource("edu:class-cancel:verify")
    @PostMapping("/cancel/pass")
    public Response<Void> passCancelRecord(@RequestBody @Validated ClassCancelVerifyReq req) {
        classCancelService.passClassCancel(req);
        return Response.success();
    }

    @Operation(summary = "拒绝退班退课审批")
    @ApiResource("edu:class-cancel:verify")
    @PostMapping("/cancel/reject")
    public Response<Void> rejectCancelRecord(@RequestBody @Validated ClassCancelVerifyReq req) {
        classCancelService.rejectClassCancel(req);
        return Response.success();
    }

    @Operation(summary = "转班调课分页查询")
    @ApiResource("edu:class-change:manage")
    @GetMapping("/change/page")
    public Response<Pagination<ClassChangeResp>> getClassChangePage(@Validated ClassChangeQuery query, @Validated PageQuery pageQuery) {
        return Response.success(Pagination.of(classChangeService.getClassChangePage(query, pageQuery)));
    }

    @Operation(summary = "转班调课详情查询")
    @ApiResource("edu:class-change:manage")
    @GetMapping("/change/detail/{id}")
    public Response<ClassChangeDetailResp> getClassChangeDetail(@PathVariable String id) {
        return Response.success(classChangeService.getClassChangeDetail(id));
    }

    @Operation(summary = "退班退课分页查询")
    @ApiResource("edu:class-cancel:manage")
    @GetMapping("/cancel/page")
    public Response<Pagination<ClassCancelResp>> getClassCancelPage(@Validated ClassCancelQuery query, @Validated PageQuery pageQuery) {
        return Response.success(Pagination.of(classCancelService.getClassCancelPage(query, pageQuery)));
    }

    @Operation(summary = "退班退课详情查询")
    @ApiResource("edu:class-cancel:manage")
    @GetMapping("/cancel/detail/{recordId}")
    public Response<ClassCancelDetailResp> getClassCancelDetail(@PathVariable String recordId) {
        return Response.success(classCancelService.getClassCancelDetail(recordId));
    }
}
